<template>
    <div style="width: 100%">
        <div id="deawer">
            <v-tableTitle :title="$t('wave.quercreat')" :btnConfig="btnConfig" @save="save"
                          @wave="wave" @deliver="deliver"></v-tableTitle>
            <div class="detailBox">
                <v-detail ref="detail"></v-detail>
            </div>
            <div class="detailListBox">
                <v-detailList ref="detailList"></v-detailList>
            </div>
        </div>
    </div>

</template>

<script>
import baseMixin from "@/mixins/BaseMixin";
import skipMixin from "@/mixins/SkipMixin";
import config from "../Config"
import tableTitle from "commons/TableTitle";
import detail from "../details/Detail"
import detailList from "../detailsList/DetailList"

export default {
    name: "",
    mixins: [baseMixin, skipMixin, config],
    data() {
        return {
            newFlag: false,
            routeData: {}
        };
    },
    computed: {
        btnConfig() {
            return [
                {label: this.$t('common.save'), certigier: !this.btnPermNameList.includes('WM05010101'), invalid: "save"},
                {label: this.$t('wave.showorderlist'), certigier: this.showOrdersListStatus||!this.btnPermNameList.includes('WM05010102'), invalid: "wave"},
                {label: this.$t('wave.savefilter'), certigier: this.deliverStatus||!this.btnPermNameList.includes('WM05010103'), invalid: "deliver"},
            ]
        }
    },
    created() {
    },
    methods: {
        deliver() {
            let detail = this.$refs.detail.detailData;
            if (detail.rtxwavetype == "") {
              this.$message.error(this.$tj('out.wavetype','app.emptyMes'));
                return;
            }
            sessionStorage.setItem("queryData", JSON.stringify(detail));
            this.$store.commit("setRouteData", detail);
            this.$router.push({name: "querybuilderSavefilter"});
        },
        wave() {
            //显示订单列表
            let detail = this.$refs.detail.detailData;
            if (detail.rtxwavetype == "") {
              this.$message.error(this.$tj('out.wavetype','app.emptyMes'));
                return;
            }
            sessionStorage.setItem("queryData", JSON.stringify(detail));
            this.$store.commit("setRouteData", detail);
            this.$router.push({name: "savefilterWave", query: {queryPageFlag: "querybulider"}});
        },
        //保存按钮
        async save() {
            let flag = this.$refs.detail.$children[0].$refs.input.submitForm("from");
            if (!flag) {
                return;
            }
            let data = {};
            let detail = this.$refs.detail.detailData;
            // let detailList = this.$refs.detailList.detailData;
            let detailList = this.$refs.detailList.$children[1].tableData
            let detailListLength = this.$refs.detailList.$children[1].tablelength;
            detailList.splice(0, detailListLength);
            detailList.forEach(item => {
                delete item.id;
            })
            // if (this.$refs.detailList.detailsFlag) {
            //     let detailflag = this.$refs.detailList.$children[1].$refs.input.submitForm("from");
            //     if (!detailflag) {
            //         return;
            //     }
            //     data = {
            //         ...detail,
            //         wpFilterdetails: [
            //             {
            //                 ...detailList,
            //                 interactionid: detail.interactionid
            //             }
            //         ]
            //     }
            data = {
                ...detail,
                wpFilterdetails: [
                    ...detailList,
                ]
            }
            // } else {
            //     data = {
            //         ...detail,
            //     }
            // }
            try {
                let res = await this.$api.post(`/insertQuerybuilderTemp`, data);
                
                    this.$message.success(res.returnMgr);
                    this.$refs.detailList.$children[1].getTableData(1, {})
                    // this.$refs.detailList.detailsFlag = false;
                    // this.$refs.detailList.detailNav = "1";

                
            } catch (e) {
                this.$message.error(e)
            }
        },
    },
    mounted() {
        ;
        if (Object.keys(this.$store.state.skip).length !== 0) {
            let data = this.$store.state.skip;
            this.routeData = data.routeData;
            this.newFlag = data.newFlag;
        } else {

            this.routeData = this.$store.state.routeData;
            this.newFlag = this.$store.state.newFlag;
        }

    },
    watch: {},
    components: {
        "v-tableTitle": tableTitle,
        "v-detail": detail,
        "v-detailList": detailList,
    }
}
</script>

<style scoped>

</style>
